#!/bin/bash
HIVE_HOME=/usr/bin/hive
yearstr=`date +%Y`
monthstr=`date +%m`
daystr=`date -d '-1 day' +%d`
quarterstr=$((($monthstr-1)/3+1))
# 执行从dwd->dws
# 先进行删除掉之前有影响的数据
${HIVE_HOME} -S -e "
--开启动态分区
set hive.exec.dynamic.partition=true;
--开启非严格模式
set hive.exec.dynamic.partition.mode=nostrict;
--开启中间压缩
set hive.exec.compress.intermediate=true;
--开启输出压缩
set hive.exec.compress.output=true;
--开启压缩模式
set hive.exec.orc.compression.strategy=COMPRESSION;
alter table macmillanedu_dws.visit_dws drop partition(yearinfo=${yearstr},quarterinfo='-1', monthinfo='-1',dayinfo='-1');
alter table macmillanedu_dws.visit_dws drop partition(yearinfo=${yearstr},quarterinfo=${quarterstr}, monthinfo='-1',dayinfo='-1');
alter table macmillanedu_dws.visit_dws drop partition(yearinfo=${yearstr},quarterinfo=${quarterstr}, monthinfo=${monthstr},dayinfo='-1');
insert into table macmillanedu_dws.visit_dws partition(yearinfo,quarterinfo,monthinfo,dayinfo)
SELECT 
count(DISTINCT sid) as sid_total,
count(DISTINCT ip) as ip_total,
count(DISTINCT session_id) as session_total,
'-1' as area,
'-1' as origin_channel,
'-1' as hourinfo,
yearinfo as time_str,
'5' as grouptype,
'4' as time_type,
yearinfo,
'-1' as quarterinfo,
'-1' as monthinfo,
'-1' as dayinfo
from macmillanedu_dwd.dwd_web_chat where  
yearinfo=${yearstr} and quarterinfo=${quarterstr}
and monthinfo=${monthstr} and  dayinfo=${daystr}
GROUP BY yearinfo
"


